package org.outlook.xnotepad;

import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

public class Process {
	private final static String regex="(?m)values\\('(.+?)',";
	private static Pattern pattern = Pattern.compile(regex);
	public static void main(String[] args) throws IOException {
		String content = FileUtils.readFileToString(new File("d:/tmp.txt"));
		Matcher matcher = pattern.matcher(content);
		StringBuffer sb = new StringBuffer();
		String temp = null;
		int index=1;
		while(matcher.find()) {
			String group = matcher.group(1);
			if(StringUtils.isBlank(temp))
				temp=group;
				
			if(temp.equals(group)) {
				matcher.appendReplacement(sb, "values("+index+",'"+group+"',");
			}else {
				index=1;
				temp=group;
				matcher.appendReplacement(sb, "values("+index+",'"+group+"',");
			}
			index++;
		}
		
		FileUtils.writeStringToFile(new File("d:/txt.txt"), sb.toString());
	}

}
